var fetch = require('@system.fetch')
var storage = require('@system.storage')

var API_ROOT = 'https://www.jianshu.com/'

var headers = {}


function realFetch(url, data = null, method = 'get') {
    console.log('┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━')
    console.log('┃ url: ', API_ROOT + url)
    console.log('┃ method: ', method)
    console.log('┃ data: ', JSON.stringify(data))
    console.log('┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━')

    return new Promise((resolve, reject) => {
        fetch.fetch({
            url: API_ROOT + url,
            data: data,
            header: headers,
            method: method,
            success: function (data) {
                resolve(data)
            },
            fail: function (data, code) {
                reject(data)
            }
        })
    })
}


function post(url, data = null, config = {}) {
    return realFetch(url, data, 'post')

}

function get(url, data = null, config = {}) {
    return realFetch(url, data, 'get')
}

export default {
    /**
     * 获取首页文章列表
     */
    getArticle() {
        return get('', null)
    },
}